#include<iostream>
#include<algorithm>

using namespace std;


bool comp(pair<int, int> A, pair<int, int> B)
{
	return A.first < B.first;
}

int main()
{
	int n, m, temp_price, temp_weight;
	cin >> n >> m; 
	pair<int, int> A[5000], temp_pair;
	for (int i = 0; i < m; i++)
	{
		cin >> temp_price >> temp_weight;
		temp_pair = pair<int, int>(temp_price, temp_weight);
		A[i] = temp_pair;
	}
	sort(A, A + m, comp);
	int now = 0, j = 0, sum = 0;
	while (true)
	{
		if (now >= n) break;
		now += A[j].second;
		sum += A[j].first * A[j].second;
		j++;
	}
	if (now > n)
	{
		sum -= (now - n) * A[j - 1].first;
	}
	cout << sum;
	return 0;
}